package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.domain.HouseVo;
import com.ruoyi.system.domain.TbPremisesInfo;
import com.ruoyi.system.service.ITbPremisesInfoService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 楼盘信息Controller
 * 
 * @author ruoyi
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/housemanager")
@CrossOrigin
public class TbPremisesInfoController extends BaseController
{
    @Autowired
    private ITbPremisesInfoService tbPremisesInfoService;

    @Autowired
    RemoteFileService remoteFileService;
//图片上传
    @PostMapping("/upload")
    public SysFile upload(MultipartFile file)
    {
        System.out.println("11111111111111");
        return  remoteFileService.upload(file).getData();

    }

    /**
     * 查询楼盘信息列表
     */
    @PreAuthorize(hasPermi = "house:housemanager:list")
    @GetMapping("/list")
    public TableDataInfo list(TbPremisesInfo tbPremisesInfo)
    {
        startPage();
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        for (TbPremisesInfo premisesInfo : list) {
            System.out.println(premisesInfo.getUrl());
        }
        return getDataTable(list);
    }

    /**
     * 导出楼盘信息列表
     */
    @PreAuthorize(hasPermi = "house:housemanager:export")
    @Log(title = "楼盘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPremisesInfo tbPremisesInfo) throws IOException
    {
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        ExcelUtil<TbPremisesInfo> util = new ExcelUtil<TbPremisesInfo>(TbPremisesInfo.class);
        util.exportExcel(response, list, "楼盘信息数据");
    }

    /**
     * 获取楼盘信息详细信息
     */
    @PreAuthorize(hasPermi = "house:housemanager:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbPremisesInfoService.selectTbPremisesInfoById(id));
    }

    /**
     * 新增楼盘信息
     */
    @PreAuthorize(hasPermi = "house:housemanager:add")
    @Log(title = "楼盘信息", businessType = BusinessType.INSERT)
    @PostMapping("add")
    @GlobalTransactional
    public AjaxResult add(@RequestBody HouseVo houseVo)
    {
        System.out.println(houseVo);
        AjaxResult ajaxResult = toAjax(tbPremisesInfoService.insertTbPremisesInfo(houseVo));
        System.out.println(ajaxResult);
        return ajaxResult;
    }

    /**
     * 修改楼盘信息
     */
    @PreAuthorize(hasPermi = "house:housemanager:edit")
    @Log(title = "楼盘信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPremisesInfo tbPremisesInfo)
    {
        return toAjax(tbPremisesInfoService.updateTbPremisesInfo(tbPremisesInfo));
    }

    /**
     * 删除楼盘信息
     */
    @PreAuthorize(hasPermi = "house:housemanager:remove")
    @Log(title = "楼盘信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPremisesInfoService.deleteTbPremisesInfoByIds(ids));
    }
}
